package com.jlnk.rxjavademo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.jlnk.rxjavademo.entity.ImageEntity;

import java.util.List;

public class ImageAdapter extends ArrayAdapter<ImageEntity> {
    private List<ImageEntity> imageDataList;

    public ImageAdapter(Context context, List<ImageEntity> imageDataList) {
        super(context, 0, imageDataList);
        this.imageDataList = imageDataList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageEntity imageData = getItem(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
        }
        TextView tvTitle = (TextView) convertView.findViewById(android.R.id.text1);
        tvTitle.setText(imageData.getTitle());
        return convertView;
    }

    public void updateData(List<ImageEntity> newImageDataList) {
        imageDataList.clear();
        imageDataList.addAll(newImageDataList);
        notifyDataSetChanged();
    }
}